import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},

{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    component: () => import('@/views/dashboard/index'),
    name: 'Dashboard',
    meta: {
      title: '数据看板',
      icon: 'dashboard',
      affix: true
    }
  }]
},
{
  path: '/cbd-mdlist',
  component: Layout,
  redirect: '/cbd-mdlist',
  children: [{
    path: 'cbd-mdlist',
    component: () => import('@/views/cbd-mdlist/index'),
    name: 'cbd-mdlist',
    meta: {
      title: '门店管理',
      icon: 'el-icon-s-shop'
    }
  }]
},
{
  path: '/cbd-mdadminlist',
  component: Layout,
  redirect: '/cbd-mdadminlist',
  children: [{
    path: 'cbd-mdadminlist',
    component: () => import('@/views/cbd-mdadminlist/index'),
    name: 'cbd-mdadminlist',
    meta: {
      title: '店员管理',
      icon: 'table'
    }
  }]
},
{
    path: '/goods',
    component: Layout,
    redirect: '/table/complex-table',
    name: 'Goods',
    meta: {
      title: '商品管理',
      icon: 'table'
    },
    children: [{
      path: 'goodslist',
      component: () => import('@/views/cbd-goods/goodslist'),
      name: 'goodslist',
      meta: {
        title: '商品列表'
      }
    },
    {
      path: 'goodsdetail',
      component: () => import('@/views/cbd-goodsdetail/goodsdetail'),
      name: 'goodsdetail',
      meta: {
        title: '添加商品'
      }
    }
    ]
  },
{
  path: '/cbd-pass',
  component: Layout,
  redirect: '/cbd-pass',
   hidden: true,
  children: [{
    path: '/cbd-pass',
    component: () => import('@/views/cbd-pass/index'),
    name: 'cbd-pass',
    meta: {
      title: '密码管理',
      icon: 'table'
    }
  }]
},
{
  path: '/cbd-showroom',
  component: Layout,
  redirect: '/cbd-showroom',
  children: [{
    path: 'cbd-showroomt',
    component: () => import('@/views/cbd-showroom/index'),
    name: 'cbd-showroom',
    meta: {
      title: '样板间',
      icon: 'table'
    }
  }]
},

{
  path: '/cbd-videolist',
  component: Layout,
  redirect: '/cbd-videolist',
  children: [{
    path: 'cbd-videolist',
    component: () => import('@/views/cbd-videolist/index'),
    name: 'cbd-videolist',
    meta: {
      title: '视频列表',
      icon: 'table'
    }
  }]
},
{
  path: '/cbd-searchmdlist',
  component: Layout,
  redirect: '/cbd-searchmdlist',
  hidden: true,
  children: [{
    path: 'cbd-searchmdlist',
    component: () => import('@/views/cbd-searchmdlist/index'),
    name: 'cbd-searchmdlist',
    meta: {
      title: '搜索门店',
      icon: 'dashboard'
    }
  }]
},
{
  path: '/cbd-adpage',
  component: Layout,
  redirect: '/cbd-adpage',
  hidden: true,
  children: [{
    path: 'cbd-adpage',
    component: () => import('@/views/cbd-adpage/index'),
    name: 'cbd-adpage',
    meta: {
      title: '创建落地页',
      icon: 'dashboard'
    }
  }]
},
{
  path: '/cbd-addad',
  component: Layout,
  redirect: '/cbd-addad',
  hidden: true,
  children: [{
    path: 'cbd-addad',
    component: () => import('@/views/cbd-addad/index'),
    name: 'cbd-addad',
    meta: {
      title: '投放广告',
      icon: 'dashboard',
      noCache: false
    }
  }]
},

{
  path: '/cbd-adlist',
  component: Layout,
  redirect: '/cbd-adlist',
  hidden: true,
  children: [{
    path: 'cbd-adlist',
    component: () => import('@/views/cbd-adlist/index'),
    name: 'cbd-adlist',
    meta: {
      title: '广告列表',
      icon: 'dashboard',
      noCache: false
    }
  }]
},
{
  path: '/cbd-goodsdetail',
  component: Layout,
  redirect: '/cbd-goodsdetail',
  hidden: true,
  children: [{
    path: 'cbd-goodsdetail',
    component: () => import('@/views/cbd-goodsdetail/goodsdetail'),
    name: 'cbd-goodsdetail',
    meta: {
      title: '产品详情',
      icon: 'dashboard',
      noCache: false
    }
  }]
},
{
  path: '/cbd-goodsSpec',
  component: Layout,
  redirect: '/cbd-goodsSpec',
  hidden: true,
  children: [{
    path: 'cbd-goodsSpec',
    component: () => import('@/views/cbd-goodsSpec/goodsSpec'),
    name: 'cbd-goodsSpec',
    meta: {
      title: '规格管理',
      icon: 'dashboard',
      noCache: false
    }
  }]
},
{
  path: '/cbd-roomimg',
  component: Layout,
  redirect: '/cbd-roomimg',
  hidden: true,
  children: [{
    path: 'cbd-roomimg',
    component: () => import('@/views/cbd-roomimg/index'),
    name: 'cbd-roomimg',
    meta: {
      title: '样板间图片',
      icon: 'dashboard',
      noCache: false
    }
  }]
},

{
  path: '/cbd-goodsImages',
  component: Layout,
  redirect: '/cbd-goodsImages',
  hidden: true,
  children: [{
    path: 'cbd-goodsImages',
    component: () => import('@/views/cbd-goodsImages/goodsImgs'),
    name: 'cbd-goodsImages',
    meta: {
      title: '商品图片详情',
      icon: 'dashboard',
      noCache: false
    }
  }]
},
{
  path: '/cbd-activelist',
  component: Layout,
  redirect: '/cbd-activelist',
  hidden: true,
  children: [{
    path: 'cbd-activelist',
    component: () => import('@/views/cbd-activelist/index'),
    name: 'cbd-activelist',
    meta: {
      title: '活动列表',
      icon: 'dashboard',
      noCache: false
    }
  }]
},
{
  path: '/cbd-addactive',
  component: Layout,
  redirect: '/cbd-addactive',
  hidden: true,
  children: [{
    path: 'cbd-addactive',
    component: () => import('@/views/cbd-addactive/index'),
    name: 'cbd-addactive',
    meta: {
      title: '添加活动',
      icon: 'dashboard',
      noCache: false
    }
  }]
}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
    path: '/cbd-org',
    component: Layout,
    redirect: '/cbd-org',
    hidden: false,
    children: [{
      path: 'cbd-org',
      component: () => import('@/views/cbd-org/index'),
      name: 'cbd-org',
      meta: {
        roles: ['cbd'],
        title: '组织架构',
        icon: 'tree-table',
        noCache: false
      }
    }]
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
